<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String _user_id=(String)session.getAttribute("_user_id");
String _type=(String)session.getAttribute("_type");
session.setAttribute("_user_id", _user_id);
session.setAttribute("_type",_type);
if(_user_id==null || _user_id.length()==0 || _type==null || _type.length()==0){
	response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
	String newLocn = "logout.jsp";
	response.setHeader("Location",newLocn);
}
%>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="com.baobaoyeye.conn.ConnMySQL" %>
<%@ page import="java.sql.ResultSet" %>
<%
ConnMySQL conn = new ConnMySQL();
String sql = "select sub_id,count from sub_stu where stu_id='"+_user_id+"';";
ResultSet rs = conn.executeQuery(sql);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Show Counts</title>
</head>
<body>
<h1>Oh! @_@ What Have You Done ???</h1>
<table border="1">

<tr>
<td>Subject Name</td>
<td>Teacher Name</td>
<td>Count</td>
</tr>
<% 
while(rs.next()){
	String subid = rs.getString(1);
	int count = rs.getInt(2);
	ConnMySQL conn1 = new ConnMySQL();
	String sql1 = "select subject_name from subject where subject_id='"+subid+"';";
	ResultSet rs1 = conn1.executeQuery(sql1);
	if(rs1.next()){
		%>
		<tr><td><%=rs1.getString(1) %></td>
		<%
	}
	rs1.close();
	ConnMySQL conn2 = new ConnMySQL();
	String sql2 ="select teacher_name from teacher where teacher_id=(select subject_teacher_id from subject where subject_id='"+subid+"');";
	ResultSet rs2 = conn2.executeQuery(sql2);
	if(rs2.next()){
		%>
		<td><%=rs2.getString(1) %></td>
		<%
	}
	rs2.close();
%>
<td>
<%if(count<60){%>
	<font color="#ff0000"><%=count%></font>
<%}else{%>
	<font color="#000000"><%=count%></font>
<%}%>
</td>
</tr> 
<%
}
rs.close();
%>
</table>
<a href="../studentplace.jsp">Back Home</a>
<a href="http://localhost:8080/teach/logout.jsp">Logout</a>
</body>
</html>